package com.ccys.cms.controller.corporateAndInsurance;

import com.ccys.cms.service.corporateAndInsurance.GroupingService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.corporateAndInsurance.GroupingDto;
import com.ccys.db.vo.corporateAndInsurance.GroupingPageQueryVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.text.ParseException;

/**
 * @program: WhiteCoat
 * @description: 分组接口
 * @author: ZhangJingCan
 * @create: 2023-12-20 16:46
 **/

@RestController
@RequestMapping("corporateAndInsurance")
@Api(tags = "corporateAndInsurance-分组接口")
public class GroupingController {

    @Autowired
    private GroupingService groupingService;


    @PostMapping("grouping")
    @ApiOperation("保存分组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id/修改必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "0-retail,1-AIA corporate,2-Direct corporate,3-AIA health shield,4-Subscription", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "policyIds", value = "type为0时不用传，其余需要传，多选用,号拼接", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "countryId", value = "countryId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "name", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "status", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "startDate", required = true, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "endDate", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "allowedRecurringAppointment", value = "0/1", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "allowedMedicationRefill", value = "0/1", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "allowedServiceReminder", value = "0/1", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "notificationAppointmentNoOfDaysBefore", value = "纯数字", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "notificationAppointmentMessage", value = "通知消息", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "notificationMedicationNoOfDaysBefore", value = "纯数字", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "notificationMedicationMessage", value = "通知消息", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "notificationServiceNoOfDaysBefore", value = "纯数字", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "notificationServiceMessage", value = "通知消息", required = false, dataType = "string", paramType = "query"),
    })
    public ResponseResult saveGrouping(@ApiIgnore GroupingDto dto) throws ParseException {
        return groupingService.saveGrouping(dto);
    }

    @DeleteMapping("grouping")
    @ApiOperation("根据ID删除分组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult deleteGrouping(@ApiIgnore GroupingDto dto) {
        return groupingService.deleteGrouping(dto);
    }


    @GetMapping("grouping")
    @ApiOperation("分页查询分组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "name模糊查询", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "0/1,查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "orderByStr",
                    value = "(默认传：t1.created_on descend),(左到右依次:t1.name,t1.type,t1.status,t2.user_fullname,t1.created_on)",
                    required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<PageInfo<GroupingPageQueryVo>, Object> findPageGrouping(@ApiIgnore GroupingDto dto) {
        return groupingService.findPageGrouping(dto);
    }


    @PutMapping("grouping/status")
    @ApiOperation("根据ID修改分组状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态：0-禁用，1-启用", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateGroupingStatus(@ApiIgnore GroupingDto dto) {
        return groupingService.updateGroupingStatus(dto);
    }

}
